<template>
  <div>
    <zbTable ref="tableRef" :api-fun="get_list" @action="action">
      <template #toolbar>
        <a-space>
          <a-button
            :type="item.types == 'add' ? 'primary' : 'dashed'"
            v-for="item in optBtn"
            :key="item.url"
            v-permission="item.url"
            @click="topAction(item)"
          >
            <template #icon>
              <plus-outlined v-if="item.types == 'add'" />
              <clear-outlined v-else-if="item.types == 'delete'" />
              <rest-outlined v-else-if="item.types == 'recycling'" />
            </template>
            <span>{{ item.name }}</span>
          </a-button>
        </a-space>
      </template>
    </zbTable>
  </div>
</template>

<script setup>
  import { ref, onMounted } from 'vue';
  import { message, Modal } from 'ant-design-vue';
  import { useRouter } from 'vue-router';
  import { actionFn } from '@/utils/action.js';
  import { daochuFn } from '@/utils/daochu.js';
  import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue';
  import zbTable from '@/components/zbTable/jewelryIndex.vue';
  import { get_list } from '@/api/jewelry/goods_bound_log';

  // 获取子组件
  const tableRef = ref(null);
  const router = useRouter();
  const { push } = useRouter();
  const optBtn = ref([]);

  onMounted(() => {
    get_list({ page: 1, page_size: 10 })
      .then(async (res) => {
        optBtn.value = res.top_button;
      })
      .catch((e) => {
        message.error(e);
      });
  });
  const topAction = (item) => {
    if (item.types == 'export') {
      daochu();
    }
  };

  /* 打开编辑弹窗 */
  const action = (data) => {};
  const done = (form) => {
    actionFn(actionData.value, form, reloadTable);
  };
  const reloadTable = () => {
    tableRef.value.reload();
  };
  const daochu = () => {
    let data = {
      url: 'warehouse/goods_bound_log/export',
      params: {},
      filename: '出入库记录列表'
    };
    daochuFn(data);
  };
</script>
